package chixing.day10.work;

import java.util.ArrayList;
import java.util.List;

public abstract class Order {
    protected String orderId;
    protected int quantity;
    protected String customerInfo;

    // 公共方法
    public abstract void processOrder();

    // 拆分订单
    public List<Order> splitOrder() {
        List<Order> orders = new ArrayList<>();
        if (this.quantity <= 1000) {
            orders.add(this);
            return orders;
        }

        // 拆分逻辑
        int splitQuantity1 = this.quantity / 2;
        int splitQuantity2 = this.quantity - splitQuantity1;

        Order order1 = this.createSplitOrder(splitQuantity1);
        Order order2 = this.createSplitOrder(splitQuantity2);

        orders.addAll(order1.splitOrder()); // 递归拆分
        orders.addAll(order2.splitOrder());

        return orders;
    }

    // 工厂方法，由子类实现具体订单创建
    protected abstract Order createSplitOrder(int quantity);

    // Getter和Setter方法

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public String getCustomerInfo() {
        return customerInfo;
    }

    public void setCustomerInfo(String customerInfo) {
        this.customerInfo = customerInfo;
    }
}
